<?php
/**
 * Created by PhpStorm.
 * User: thanatos
 * Date: 2017/11/21
 * Time: 下午1:17
 */

namespace common\components;


class CloudSmser extends \daixianceng\smser\CloudSmser{
    
    public $url = 'http://api.sms.cn/sms/?';
    
    /**
     * @inheritdoc
     */
    public function send($mobile, $content)
    {
        if (parent::send($mobile, $content)) {
            return true;
        }
        
        
        $data = [
            'ac' => 'send',
            'uid' => $this->username,
            'pwd' => $this->password,
            'mobile' => $mobile,
            'content' => $content
        ];
        
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->url. http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $result = curl_exec($ch);
        var_dump($result);exit;
        curl_close($ch);
        
        $resultArr = [];
        parse_str($result, $resultArr);
        
        $this->state = isset($resultArr['stat']) ? (string) $resultArr['stat'] : null;
        $this->message = isset($resultArr['message']) ? (string) $resultArr['message'] : null;
        
        return $this->state === '100';
    }
}